module LEDHandler (
	input [15:0] PC_val,
	input ModeSel,
	output [9:0] LED
);

	wire is_ge_1000, is_ge_2000, is_ge_3000, is_ge_4000, is_ge_5000;
	wire is_ge_6000, is_ge_7000, is_ge_8000, is_ge_9000;

	MyComparator16bit cmp_ge_1000 (.A(PC_val), .B(16'd1000), .GT(is_ge_1000), .LT(), .EQ());
	MyComparator16bit cmp_ge_2000 (.A(PC_val), .B(16'd2000), .GT(is_ge_2000), .LT(), .EQ());
	MyComparator16bit cmp_ge_3000 (.A(PC_val), .B(16'd3000), .GT(is_ge_3000), .LT(), .EQ());
	MyComparator16bit cmp_ge_4000 (.A(PC_val), .B(16'd4000), .GT(is_ge_4000), .LT(), .EQ());
	MyComparator16bit cmp_ge_5000 (.A(PC_val), .B(16'd5000), .GT(is_ge_5000), .LT(), .EQ());
	MyComparator16bit cmp_ge_6000 (.A(PC_val), .B(16'd6000), .GT(is_ge_6000), .LT(), .EQ());
	MyComparator16bit cmp_ge_7000 (.A(PC_val), .B(16'd7000), .GT(is_ge_7000), .LT(), .EQ());
	MyComparator16bit cmp_ge_8000 (.A(PC_val), .B(16'd8000), .GT(is_ge_8000), .LT(), .EQ());
	MyComparator16bit cmp_ge_9000 (.A(PC_val), .B(16'd9000), .GT(is_ge_9000), .LT(), .EQ());

	wire [9:0] led_stage_0 = 10'b0000000001;
	wire [9:0] led_stage_1 = 10'b0000000011;
	wire [9:0] led_stage_2 = 10'b0000000111;
	wire [9:0] led_stage_3 = 10'b0000001111;
	wire [9:0] led_stage_4 = 10'b0000011111;
	wire [9:0] led_stage_5 = 10'b0000111111;
	wire [9:0] led_stage_6 = 10'b0001111111;
	wire [9:0] led_stage_7 = 10'b0011111111;
	wire [9:0] led_stage_8 = 10'b0111111111;
	wire [9:0] led_stage_9 = 10'b1111111111;

	wire [9:0] mux_out_1, mux_out_2, mux_out_3, mux_out_4, mux_out_5;
	wire [9:0] mux_out_6, mux_out_7, mux_out_8, mux_out_9;
	wire [9:0] led_mode0;

	genvar i;
	generate
	for (i = 0; i < 10; i = i + 1) begin : gen_mode0_mux
		Mux2To1 mux1 (.sel(is_ge_1000), .a(led_stage_0[i]), .b(led_stage_1[i]), .out(mux_out_1[i]));
		Mux2To1 mux2 (.sel(is_ge_2000), .a(mux_out_1[i]),   .b(led_stage_2[i]), .out(mux_out_2[i]));
		Mux2To1 mux3 (.sel(is_ge_3000), .a(mux_out_2[i]),   .b(led_stage_3[i]), .out(mux_out_3[i]));
		Mux2To1 mux4 (.sel(is_ge_4000), .a(mux_out_3[i]),   .b(led_stage_4[i]), .out(mux_out_4[i]));
		Mux2To1 mux5 (.sel(is_ge_5000), .a(mux_out_4[i]),   .b(led_stage_5[i]), .out(mux_out_5[i]));
		Mux2To1 mux6 (.sel(is_ge_6000), .a(mux_out_5[i]),   .b(led_stage_6[i]), .out(mux_out_6[i]));
		Mux2To1 mux7 (.sel(is_ge_7000), .a(mux_out_6[i]),   .b(led_stage_7[i]), .out(mux_out_7[i]));
		Mux2To1 mux8 (.sel(is_ge_8000), .a(mux_out_7[i]),   .b(led_stage_8[i]), .out(mux_out_8[i]));
		Mux2To1 mux9 (.sel(is_ge_9000), .a(mux_out_8[i]),   .b(led_stage_9[i]), .out(mux_out_9[i]));
	end
	endgenerate

	assign led_mode0 = mux_out_9;

	wire is_ge_0, is_ge_12, is_ge_24, is_ge_36, is_ge_48;
	wire is_ge_60, is_ge_72, is_ge_84, is_ge_96, is_ge_108;

	MyComparator16bit cmp_ge_0   (.A(PC_val), .B(16'd0),   .GT(is_ge_0),   .LT(), .EQ());
	MyComparator16bit cmp_ge_12  (.A(PC_val), .B(16'd12),  .GT(is_ge_12),  .LT(), .EQ());
	MyComparator16bit cmp_ge_24  (.A(PC_val), .B(16'd24),  .GT(is_ge_24),  .LT(), .EQ());
	MyComparator16bit cmp_ge_36  (.A(PC_val), .B(16'd36),  .GT(is_ge_36),  .LT(), .EQ());
	MyComparator16bit cmp_ge_48  (.A(PC_val), .B(16'd48),  .GT(is_ge_48),  .LT(), .EQ());
	MyComparator16bit cmp_ge_60  (.A(PC_val), .B(16'd60),  .GT(is_ge_60),  .LT(), .EQ());
	MyComparator16bit cmp_ge_72  (.A(PC_val), .B(16'd72),  .GT(is_ge_72),  .LT(), .EQ());
	MyComparator16bit cmp_ge_84  (.A(PC_val), .B(16'd84),  .GT(is_ge_84),  .LT(), .EQ());
	MyComparator16bit cmp_ge_96  (.A(PC_val), .B(16'd96),  .GT(is_ge_96),  .LT(), .EQ());
	MyComparator16bit cmp_ge_108 (.A(PC_val), .B(16'd108), .GT(is_ge_108), .LT(), .EQ());

	wire [9:0] led_mode1;
	assign led_mode1[0] = ~is_ge_0;
	assign led_mode1[1] = ~is_ge_12;
	assign led_mode1[2] = ~is_ge_24;
	assign led_mode1[3] = ~is_ge_36;
	assign led_mode1[4] = ~is_ge_48;
	assign led_mode1[5] = ~is_ge_60;
	assign led_mode1[6] = ~is_ge_72;
	assign led_mode1[7] = ~is_ge_84;
	assign led_mode1[8] = ~is_ge_96;
	assign led_mode1[9] = ~is_ge_108;

	genvar j;
	generate
	for (j = 0; j < 10; j = j + 1) begin : gen_mode_select
		Mux2To1 final_mux (
			 .sel(ModeSel),
			 .a(led_mode0[j]),
			 .b(led_mode1[j]),
			 .out(LED[j])
		);
	end
	endgenerate

endmodule
